﻿Imports Microsoft.Practices.EnterpriseLibrary.Data
Imports Seuss.EnterpriseLibrary.DataAccess
Imports Seuss.EnterpriseLibrary.BusinessLogic
Imports System.Web
Imports System.Data

Partial Class Consulta_DO_Marcaciones
    Inherits System.Web.UI.Page
    Dim cPerJuridica As String

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Response.Expires = -1
        Response.AddHeader("Pragma", "no-cache")
        Response.AddHeader("cache-control", "private")
        Response.CacheControl = "no-cache"

        If Not Page.IsPostBack Then
            Call MostrarFiliales()
            For i = 1 To 31
                ddlI_dia.Items.Add(IIf(i >= 1 And i < 10, "0" + i.ToString, i.ToString))
                ddlF_dia.Items.Add(IIf(i >= 1 And i < 10, "0" + i.ToString, i.ToString))
            Next

            For i = 1 To 12
                Dim li As New ListItem
                li.Text = ObtieneMes(i)
                li.Value = IIf(i >= 1 And i < 10, "0" + i.ToString, i.ToString)
                ddlI_mes.Items.Add(li)
                ddlF_mes.Items.Add(li)
            Next

            For i = Year(DateTime.Now) To 2005 Step -1
                ddlI_anio.Items.Add(i)
                ddlF_anio.Items.Add(i)
            Next

            ddlI_mes.SelectedValue = Month(DateTime.Now)
            ddlF_mes.SelectedValue = Month(DateTime.Now)
            Using Seguridad As New BLL_Administracion
                Seguridad.Set_Transaccion_Insert(Nothing, 100401, IdentityUser.UserCode, My.Request.UserHostAddress.ToString, CrearXMLTransaccion("Consulta Pagina Movil", "/Pagina|" + My.Request.Url.Segments(My.Request.Url.Segments.Length - 1).ToString))
            End Using
        End If
    End Sub

    Private Function ObtieneMes(ByVal nromes As Integer) As String
        Dim mes As String = ""
        Select Case nromes
            Case 1
                mes = "Ene"
            Case 2
                mes = "Feb"
            Case 3
                mes = "Maz"
            Case 4
                mes = "Abr"
            Case 5
                mes = "Mar"
            Case 6
                mes = "Jun"
            Case 7
                mes = "Jul"
            Case 8
                mes = "Ago"
            Case 9
                mes = "Set"
            Case 10
                mes = "Oct"
            Case 11
                mes = "Nov"
            Case 12
                mes = "Dic"
        End Select
        Return mes
    End Function

    Private Sub MostrarFiliales()
        Dim ldrMnu As New List(Of IDataReader)
        Using ObjPool As New PoolDbCommand()
            Dim ObjMnu As New DAL_Kiosco(ObjPool.Database)
            ObjPool.AddDbCommand(ObjMnu.Get_cPerJuridicaDocente_by_cPerCodigo(IdentityUser.UserCode), PoolDbCommand.PoolDbCommandResultType.Query)
            ObjPool.Pooling(Nothing, ldrMnu, True)
            ddlFilial.DataSource = Helper.LoadDataTable(ldrMnu(0))
            ddlFilial.DataTextField = "cPerApellido"
            ddlFilial.DataValueField = "cPerJuridica"
            ddlFilial.DataBind()
        End Using
        ldrMnu(0).Close()
        ldrMnu = Nothing
    End Sub

    Private Sub CargarMarcaciones(ByVal cPerJuridica As String, ByVal dFechaIni As String, ByVal dFechaFin As String)
        Dim ldr As New List(Of IDataReader)
        Dim DivPrincipal As New StringBuilder
        Dim DivEscuela As New StringBuilder
        Dim Escuela As String = ""
        Dim Fecha As String = ""

        DivPrincipal.Append("<table border=0 width='100%'>")

        Using ObjPool As New PoolDbCommand()
            Dim ObjUsuario As New DAL_Kiosco(ObjPool.Database)
            ObjPool.AddDbCommand(ObjUsuario.Get_Marcaciones_By_cPerCodigo(cPerJuridica, dFechaIni, dFechaFin, IdentityUser.UserCode), PoolDbCommand.PoolDbCommandResultType.Query)
            ObjPool.Pooling(Nothing, ldr, True)
            ObjUsuario = Nothing
            While ldr(0).Read
                If Escuela <> ldr(0).Item("cUniOrgNombre").ToString Then
                    DivPrincipal.Append("<tr style='color:#FFFFFF'>")
                    DivPrincipal.Append("   <td style='font-size:10px;color:#000000; text-align:left;font-weight :bold' colspan='6'><img src='../Imagenes/Ok2.gif' />ESCUELA DE " + ldr(0).Item("cUniOrgNombre").ToString + "</td>")
                    DivPrincipal.Append("</tr>")

                    DivPrincipal.Append("<tr style='color:#FFFFFF'>")
                    DivPrincipal.Append("   <td style='background-color:#666666;font-size:12px;width:15%;'><span style='font-weight:bold'>Fecha:</span></td>")
                    DivPrincipal.Append("   <td style='background-color:#666666;font-size:12px;width:15%;'><span style='font-weight:bold'>IN:</span></td>")
                    DivPrincipal.Append("   <td style='background-color:#666666;font-size:12px;width:15%;'><span style='font-weight:bold'>SA:</span></td>")
                    DivPrincipal.Append("   <td style='background-color:#666666;font-size:12px;width:10%;'><span style='font-weight:bold'>NT:</span></td>")
                    DivPrincipal.Append("   <td style='background-color:#666666;font-size:12px;width:10%;'><span style='font-weight:bold'>F:</span></td>")
                    DivPrincipal.Append("   <td style='background-color:#666666;font-size:12px;width:10%;'><span style='font-weight:bold'>I:</span></td>")
                    DivPrincipal.Append("   <td style='background-color:#666666;font-size:12px;width:10%;'><span style='font-weight:bold'>T:</span></td>")
                    DivPrincipal.Append("</tr>")

                End If

                'If Fecha <> ldr(0).Item("dFecha").ToString Then
                '    DivPrincipal.Append("<tr style='color:#FFFFFF'>")
                '    DivPrincipal.Append("   <td style='background-color:#666666;font-size:9px;' colspan='6'>" + ldr(0).Item("dFecha").ToString + " - Hor. Ingreso: " + ldr(0).Item("HorarioIngreso").ToString + " - Hor. Salida: " + ldr(0).Item("HorarioSalida").ToString + "</td>")
                '    DivPrincipal.Append("</tr>")
                'End If

                DivPrincipal.Append("<tr>")
                DivPrincipal.Append("   <td style='font-size:10px;width:15%;'>" + ldr(0).Item("dFecha").ToString + "<br/>HI: " + ldr(0).Item("HorarioIngreso").ToString + "<br/>HS: " + ldr(0).Item("HorarioSalida").ToString + "</td>")
                DivPrincipal.Append("   <td style='font-size:10px;width:15%;'>" + ldr(0).Item("Ingreso").ToString + "</td>")
                DivPrincipal.Append("   <td style='font-size:10px;width:15%;'>" + ldr(0).Item("Salida").ToString + "</td>")
                DivPrincipal.Append("   <td style='font-size:10px;width:10%;'>" + ldr(0).Item("NoTrabajadas").ToString + "</td>")
                DivPrincipal.Append("   <td style='font-size:10px;width:10%;'>" + ldr(0).Item("Faltas").ToString + "</td>")
                DivPrincipal.Append("   <td style='font-size:10px;width:10%;'>" + ldr(0).Item("Incompletas").ToString + "</td>")
                DivPrincipal.Append("   <td style='font-size:10px;width:10%;'>" + ldr(0).Item("Tardanzas").ToString + "</td>")
                DivPrincipal.Append("</tr>")

                Escuela = ldr(0).Item("cUniOrgNombre").ToString
                Fecha = ldr(0).Item("dFecha").ToString
            End While
        End Using

        DivPrincipal.Append("</table>")
        lblMarcaciones.Text = DivPrincipal.ToString
    End Sub

    Protected Sub LoginButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles LoginButton.Click
        Call CargarMarcaciones(ddlFilial.SelectedValue.ToString, ddlI_anio.SelectedValue.ToString + ddlI_mes.SelectedValue.ToString + ddlI_dia.SelectedValue.ToString, ddlF_anio.SelectedValue.ToString + ddlF_mes.SelectedValue.ToString + ddlF_dia.SelectedValue.ToString)
    End Sub
End Class
